package com.demo;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo5Lambda {
    public static void main(String[] args) {
        List<Model> list = new ArrayList<>();
        list.add(new Model("a", 10));
        list.add(new Model("g", 50));
        list.add(new Model("g", 50));
        list.add(new Model("d", 90));

        Comparator<Model> comparator = (x, y) -> {
            if (x.getAge() != y.getAge()) {
                return x.getAge() - y.getAge();
            } else {
                return x.getName().compareTo(y.getName());
            }
        };

        Collections.sort(list, comparator);


        for (Model m : list
        ) {
            System.out.println(m);
        }
    }

}

class Model {
    private String name;
    private int age;

    public Model(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Model{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
